﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Controls;

namespace CreaMotion.ValueConverters
{
    public class String2RelationshipType : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //Enum To String
            String val = ((Interfaces.Field.RType)value).ToString("F");
            return val;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Interfaces.Field.RType returnData = Interfaces.Field.RType.one;

            try
            {
                //Enum To String
                string val = ((TextBlock)value).Text;
                returnData = (Interfaces.Field.RType)Enum.Parse(typeof(Interfaces.Field.RType), val);
            }
            catch { }

            return returnData;
        }
    }
}
